<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>首页</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="/pear/component/pear/css/pear.css" />
		<script src="/js/jquery-3.2.1.min.js"></script>

		<style type="text/css">
			img{
				    width: 100px;
    				height: 100px;
			}
		</style>
	</head>
	<body class="pear-container">
		<div class="layui-row layui-col-space10">
			<div class="layui-col-md12">
				<div class="layui-row layui-col-space10" id="father">
				</div>
			</div>
		</div>


		<script src="/pear/component/layui/layui.js"></script>
		<script src="/pear/component/pear/pear.js"></script>
		<script>
			layui.use('layer', function(){
				var layer = layui.layer;
			});
			// 用来装用户名
			var userName_array = [null];
			// var i = 0;

			// 文档加载事件
			$(function () {
				$.ajax({
					url: "/apply/applyList",
					success:function (data) {
						console.log(data[0].Dealed);
						var html = '';
						for (let i=0; i < data.length; i++) {
							console.log(data[i].Dealed);
							if (data[i].Dealed == null){
								html +=
										'<div class="layui-col-md4" id="model_'+i+'">'+
										'<div class="layui-card">'+
										'<div class="layui-card-header">'+
										'<div class="layui-btn-container" style="margin-left: 230px;">'+
										'<button type="button" class="layui-btn" onclick="agree('+i+')">处理</button> '+
										'<button type="button" class="layui-btn layui-btn-danger" onclick="refuse('+i+')">拒绝</button> '+
										'</div>'+
										'</div>'+
										'<div class="layui-card-body">'+
										'<div class="layui-row layui-col-space10">'+
										'<div class="layui-col-md4 layui-col-sm4 layui-col-xs4 img">'+
										'<img src="/pear/my/img/tx.jpg"/>'+
										'</div>'+
										'<div class="layui-col-md8 layui-col-sm8 layui-col-xs8" >'+

										'<p><strong id="userName_'+i+'">'+data[i].customerName+'</strong></p>'+
										'<p>'+
										'<i class="layui-icon layui-icon-location"></i>'+
										data[i].address+
										'</p>'+
										'<p>E-Mail:'+data[i].email+'</p>'+
										'<p>服务类型：'+data[i].serviceType+'</p>'+
										'<p>需求说明：'+data[i].Note+'</p>'+
										'</div>'+

										'</div>'+
										'</div>'+

										'</div>	'+
										'</div>';
							}
						}
						$("#father").html(html);
					}
				})
			})

			// 设置点击拒绝后的事件
			function refuse(num) {
				var id = 'model_'+num+"";
				console.log(id);
				$('#'+id).css({"display":"none"});
			}
			// 设置点击处理后的事件
			function agree(num) {
				var id =  'model_'+num+"";
				console.log('test:'+id)
				layer.open({
					type:2,

					title: '服务申请',
					area: ['600px', '560px'],
					content:'/houtai/dealApply',
					success:function (layero, index) {
						var body = layer.getChildFrame('body', index);
						// 找到点击的是哪个申请card
						var id = 'userName_'+num+"";
						console.log(id);
						var userName = $("#"+id).html();

						var Id = null;

						body.contents().find("#userName").val(userName);

						// 通过用户名进行查询 将查询到的数据放到弹出层上
						$.ajax({
							url: '/apply/selectApply',
							data: {"userName": userName},
							success: function (data) {

								body.contents().find("#calender").val(data[num].serviceDate);
								body.contents().find("#content").val(data[num].Note);
								body.contents().find("#customerId").val(data[num].Id);
								console.log("8888888");
								console.log(data[num].Id);
								console.log("9999999");

							}
						})
					}

				})
			}

		</script>

	</body>
</html>
